package course.service.impl;

import course.dao.SubjectDao;
import course.dao.impl.SubjectDaoImpl;
import course.pojo.entity.Subject;
import course.pojo.vo.Page;
import course.service.SubjectService;
import course.utils.JDBCUtil;

import java.sql.Connection;
import java.util.List;

/**
 * @author HLF
 * @date 2022/6/30 20:52
 */
public class SubjectServiceImpl implements SubjectService {
    private SubjectDao subjectDao = new SubjectDaoImpl();

    @Override
    public Subject getById(Integer suid) {
        Connection connection = JDBCUtil.getConnection();
        Subject subject = subjectDao.getById(suid, connection);
        JDBCUtil.closeConnection(connection);
        return subject;
    }

    @Override
    public int addSubject(Subject subject) {
        Connection connection = JDBCUtil.getConnection();
        int i = subjectDao.addSubject(subject, connection);
        JDBCUtil.closeConnection(connection);
        return i;
    }

    @Override
    public int updateById(Subject subject) {
        Connection connection = JDBCUtil.getConnection();
        int i = subjectDao.updateById(subject, connection);
        JDBCUtil.closeConnection(connection);
        return i;
    }

    @Override
    public int deleteById(Integer suid) {
        Connection connection = JDBCUtil.getConnection();
        int i = subjectDao.deleteById(suid, connection);
        JDBCUtil.closeConnection(connection);
        return i;
    }

    @Override
    public List<Subject> getList() {
        Connection connection = JDBCUtil.getConnection();
        List<Subject> list = subjectDao.getList(connection);
        JDBCUtil.closeConnection(connection);
        return list;
    }

    /**/

    @Override
    public int deleteSelect(List<Integer> ids) {
        Connection connection = JDBCUtil.getConnection();
        int i = subjectDao.deleteSelect(ids, connection);
        JDBCUtil.closeConnection(connection);
        return i;
    }

    @Override
    public long count() {
        Connection connection = JDBCUtil.getConnection();
        long count = subjectDao.count(connection);
        JDBCUtil.closeConnection(connection);
        return count;
    }

    @Override
    public Page<Subject> page(Integer pageNo) {
        Connection connection = JDBCUtil.getConnection();
        Page<Subject> page = subjectDao.page(pageNo, connection);
        JDBCUtil.closeConnection(connection);
        return page;
    }

    @Override
    public Page<Subject> page2(Integer pageNo, Integer cid) {
        Connection connection = JDBCUtil.getConnection();
        Page<Subject> page = subjectDao.page2(pageNo, cid, connection);
        JDBCUtil.closeConnection(connection);
        return page;
    }

    @Override
    public Page<Subject> ownPage(Integer pageNo, Integer tid) {
        Connection connection = JDBCUtil.getConnection();
        Page<Subject> page = subjectDao.ownPage(pageNo, tid, connection);
        JDBCUtil.closeConnection(connection);
        return page;
    }

    @Override
    public Page<Subject> ownPage2(Integer pageNo, Integer sid) {
        Connection connection = JDBCUtil.getConnection();
        Page<Subject> page = subjectDao.ownPage2(pageNo, sid, connection);
        JDBCUtil.closeConnection(connection);
        return page;
    }

    @Override
    public Page<Subject> query(String cname, Integer pageNo) {
        Connection connection = JDBCUtil.getConnection();
        Page<Subject> page = subjectDao.query(cname, pageNo, connection);
        JDBCUtil.closeConnection(connection);
        return page;
    }

    @Override
    public Subject getBySuname(String suname) {
        Connection connection = JDBCUtil.getConnection();
        Subject bySuname = subjectDao.getBySuname(suname, connection);
        JDBCUtil.closeConnection(connection);
        return bySuname;
    }

    @Override
    public List<Subject> selectBathByIds(List<Integer> ids) {
        Connection connection = JDBCUtil.getConnection();
        List<Subject> subjects = subjectDao.selectBathByIds(ids, connection);
        JDBCUtil.closeConnection(connection);
        return subjects;
    }
}
